<template>
  <div class="number-scroll">
    <div class="scrolltitle">{{ scrollLabel }}</div>
    <li
      class="number-item"
      v-for="(item, index) in computeNumber"
      :key="index"
      :class="[iflast ? 'last' : '']"
    >
      <span>
        <i ref="numberItem">0123456789</i>
      </span>
    </li>
  </div>
</template>
<script setup>
import { ref, onMounted, watch } from 'vue'
// import { debounce } from '@/utils/index'
const props = defineProps({
  numValue: {
    type: String,
    default: () => '1234'
  },
  scrollLabel: {
    type: String,
    default: () => '居民区'
  },
  iflast: Boolean
})
let computeNumber = ref(['0', '0', '0', '0', '0', '9', '1', '7'])
let numberItem = ref(null)
onMounted(() => {
  computeNumber.value = props.numValue.split('')
  increaseNumber()
})
const increaseNumber = () => {
  //   let self = this
  //   this.timer = setInterval(() => {
  //     self.setNumberTransform()
  //   }, 500)
  //   debounce(setNumberTransform(), 500)
  setNumberTransform()
}
const setNumberTransform = () => {
  let numberItems = numberItem.value
  let numberArr = computeNumber.value.filter((item) => !isNaN(item))
  for (let index = 0; index < numberItems.length; index++) {
    let elem = numberItems[index]
    elem.style.transform = `translate(-50%, -${numberArr[index] * 10}%)`
  }
}
// const init = () => {
//   let numberItems = this.$refs.numberItem
//   for (let index = 0; index < numberItems.length; index++) {
//     let elem = numberItems[index]
//     elem.style.transform = `translate(-50%, 0}%)`
//   }
// }
watch(
  () => props.numValue,
  (newValue, oldValue) => {
    computeNumber.value = newValue.split('')
    increaseNumber()
  }
)
</script>
<style scoped lang="scss">
.number-scroll {
  width: auto;
  display: flex;
  position: relative;
  font-size: 72px;
  font-family: YouSheBiaoTiHei;
  font-weight: 400;
  color: #91dcff;
  //   justify-content: space-around;
  .scrolltitle {
    width: 400px;
    position: absolute;
    top: 53%;
    left: 50%;
    font-size: 32px;
    font-family: YouSheBiaoTiHei;
    font-weight: 400;
    color: #ffffff;
    transform: translateX(-50%);
    text-align: center;
  }
  .number-item {
    width: 50px;
    height: 80px;
    // margin-right: 9px;
    // background-color: #425354;
    span {
      position: relative;
      display: inline-block;
      width: 100%;
      height: 100%;
      writing-mode: vertical-rl;
      text-orientation: upright;
      overflow: hidden;
      i {
        cursor: pointer;
        position: absolute;
        top: 7px;
        left: 50%;
        transform: translate(-50%, 0);
        transition: transform 1.5s ease-in-out;
        // letter-spacing: 10px;
      }
    }
  }
  .number-item:last-child {
    position: relative;
    &::after {
      content: '';
      position: absolute;
      width: 1px;
      height: 80px;
      border: 2px solid #b6e7ff;
      top: 25px;
      left: 110px;
    }
  }
  .number-item.last {
    &::after {
      width: 0;
      height: 0;
    }
  }
}
</style>
